
$(function() {
	var offWidth = document.body.clientWidth
	// 设计稿1rem = 100px
	document.getElementsByTagName("html")[0].style.fontSize = offWidth*(100/1920) + 'px'; //把rem的值复制给顶级标签html的font-size
	console.log('offWidth:'+offWidth)

	window.onresize = function(){
	    location.reload()
	}
	
    validateRule();
    
    $(".i-checks").iCheck({checkboxClass:"icheckbox_square-green-login"});
	$('.imgcode').click(function() {
		var url = ctx + "captcha/captchaImage?type=" + captchaType + "&s=" + Math.random();
		$(".imgcode").attr("src", url);
	});
    
});


$.validator.setDefaults({
    submitHandler: function() {
		application();
    }
});

function application() {
	$.modal.loading($("#applicationSubmit").data("loading"));
	var applyArea = $.common.trim($("input[name='applyArea']").val());
    var orgName = $.common.trim($("input[name='orgName']").val());
    var applyName = $.common.trim($("input[name='applyName']").val());
    var applyPhone = $.common.trim($("input[name='applyPhone']").val());
    $.ajax({
        type: "post",
        url: ctx + "abutment/application",
        data: {
        	"applyArea": applyArea,
        	"orgName": orgName,
        	"applyName": applyName,
            "applyPhone": applyPhone
        },
        success: function(r) {
            if (r.code == 0) {
            	$.modal.closeLoading();
            	$.modal.msg("已提交申请，我们将尽快与您联系");
            	location.href = ctx + "abutment/notopen";
            } else {
            	$.modal.closeLoading();
            	$('.imgcode').click();
            	$.modal.msg(r.msg);
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#applicationForm").validate({
        rules: {
        	applyArea: {
                required: true
            },
            orgName: {
                required: true
            },
            applyName: {
                required: true
            },
            applyPhone: {
                required: true
            }
        },
        messages: {
        	applyArea: {
                required: "",
            },
            orgName: {
                required: "",
            },
            applyName: {
                required: "",
            },
            applyPhone: {
                required: "",
            }
        }
    })
}



